package com.fishv.fishvdianping.controller;

import com.fishv.fishvdianping.common.ErrorCode;
import com.fishv.fishvdianping.common.Result;
import com.fishv.fishvdianping.service.SeckillVoucherService;
import com.fishv.fishvdianping.service.VoucherService;
import com.fishv.fishvdianping.utils.ThrowUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yuwei
 * @date 15:00 2024/10/21
 */
@RestController
@RequestMapping("/voucher")
public class VoucherController {
    @Resource
    private VoucherService voucherService;
    @Resource
    private SeckillVoucherService secKillService;

    /**
     *
     * 获取秒杀券
     * @param id
     * @return
     */
    @GetMapping("/secKillVouchers/{id}")
    public Result secKillVouchers(@PathVariable("id") Long id){
        ThrowUtils.throwIf(id == null, ErrorCode.PARAMS_ERROR,"id不能为空");
        return Result.ok(secKillService.getSecKillVoucher(id));
    }
}
